﻿namespace MicroCloud.Filter
{
    /// <summary>
    /// 分页请求
    /// </summary>
    public class PageRequest
    {
        /// <summary>
        /// 初始化一个分页请求 <see cref="PageRequest"/> 的新实例
        /// </summary>
        public PageRequest()
        {
            PageCondition = new PageCondition(1, 20);
            FilterGroup = new FilterGroup();
        }

        #region 属性
        /// <summary>
        /// 获取或设置 分页条件
        /// </summary>
        public PageCondition PageCondition { get; set; }

        /// <summary>
        /// 获取或设置 查询条件组
        /// </summary>
        public FilterGroup FilterGroup { get; set; }

        #endregion

        /// <summary>
        /// 添加默认排序条件
        /// <para>只有排序为空时有效</para>
        /// </summary>
        /// <param name="sortConditions"></param>
        public void AddDefaultSortCondition(params SortCondition[] sortConditions)
        {
            Check.NotNullOrEmpty(sortConditions, nameof(sortConditions));
            if (PageCondition.SortConditions.Length == 0)
            {
                PageCondition.SortConditions = sortConditions;
            }
        }

    }
}